ig.module(
	'game.entities.player'
)
.requires(
	'impact.entity',
        'game.entities.base.entityBase'
)
.defines(function()
{
    EntityPlayer = EntityEntityBase.extend(
    {
        size: {x:30, y:21},     
	collides: ig.Entity.COLLIDES.ACTIVE,
        animSheet: new ig.AnimationSheet('media/images/player.png', 30, 21),
	drawBox: true,
	walkSpeed: 1300,
	
        init: function(x, y, settings)
        {
            ig.global.touched = 0;
            this.parent(x, y, settings);
            this.addAnim('Idle', 1, [0]);
        },
        
        touches: function(other)
        {
	    var isTouched = this.parent(other);
	    
            if (other instanceof EntityPickObject)
            {                
                if (isTouched == true && other.picked == false)
		{
		    ig.global.touched++;		    
		    other.onPick();
		}
		else if (this.picked == true)
		{
		    other.kill();
		}		
            }
            
            return isTouched;            
        },
        
        update: function()
        {
            this.parent();
            
	    
            if (ig.input.state('up'))
            {
                this.vel.y = -this.walkSpeed;
		this.currentAnim.angle = 0.5 * Math.PI;
		this.currentAnim.flip.x = true;
            }
            else if (ig.input.state('down'))
            {
                this.vel.y = this.walkSpeed;
		this.currentAnim.angle = -0.5 * Math.PI;
		this.currentAnim.flip.x = true;
            }
            else
            {
                this.vel.y = 0;                
            }
	    
            if (ig.input.state('left'))
            {
                this.vel.x = -this.walkSpeed;
		this.currentAnim.angle = 0;
		this.currentAnim.flip.x = true;
            }
            else if (ig.input.state('right'))
            {
                this.vel.x = this.walkSpeed;
		this.currentAnim.angle = 0;		
		this.currentAnim.flip.x = false;
            }
            else
            {
                this.vel.x = 0;                
            }	    
        },
        
        draw: function()
        {
            this.parent();
        },        
    });
});